<%--
  Created by IntelliJ IDEA.
  User: kiss2
  Date: 2025/4/24
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>商品管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="no-referrer">
    <!-- 引入Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #2563eb;
            --primary-light: #3b82f6;
            --primary-dark: #1d4ed8;
            --success-color: #10b981;
            --danger-color: #ef4444;
            --warning-color: #f59e0b;
            --text-color: #1e293b;
            --text-light: #64748b;
            --border-color: #e2e8f0;
            --bg-color: #f8fafc;
            --card-bg: #ffffff;
            --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
            --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
            --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
            --radius-sm: 4px;
            --radius-md: 6px;
            --radius-lg: 8px;
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.6;
            padding: 20px;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            background-color: var(--card-bg);
            border-radius: var(--radius-lg);
            box-shadow: var(--shadow-md);
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid var(--border-color);
        }

        .header-actions {
            display: flex;
            gap: 15px;
            align-items: center;
        }

        h2 {
            color: var(--text-color);
            font-size: 24px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        h2 i {
            color: var(--primary-color);
        }

        .search-box {
            position: relative;
        }

        .search-box input {
            padding: 10px 15px 10px 40px;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            font-size: 14px;
            width: 250px;
            transition: var(--transition);
        }

        .search-box input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
            width: 300px;
        }

        .search-box i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-light);
        }

        .add-btn {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 10px 20px;
            background-color: var(--primary-color);
            color: white;
            text-decoration: none;
            border-radius: var(--radius-md);
            font-weight: 500;
            transition: var(--transition);
            border: none;
            cursor: pointer;
            font-size: 14px;
        }

        .add-btn:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: var(--shadow-md);
        }

        .goods-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            border-radius: var(--radius-lg);
            overflow: hidden;
        }

        .goods-table thead {
            background-color: var(--primary-color);
            color: white;
        }

        .goods-table th {
            padding: 15px;
            text-align: left;
            font-weight: 500;
            position: sticky;
            top: 0;
            z-index: 10;
        }

        .goods-table td {
            padding: 15px;
            border-bottom: 1px solid var(--border-color);
            vertical-align: middle;
        }

        .goods-table tr:last-child td {
            border-bottom: none;
        }

        .goods-table tr:hover {
            background-color: rgba(37, 99, 235, 0.02);
        }

        .goods-img {
            width: 120px;
            height: 80px;
            object-fit: cover;
            border-radius: var(--radius-sm);
            box-shadow: var(--shadow-sm);
            transition: transform 0.3s ease;
            border: 1px solid var(--border-color);
        }

        .goods-img:hover {
            transform: scale(1.05);
        }

        .no-image {
            width: 120px;
            height: 80px;
            background-color: #f1f5f9;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--text-light);
            border-radius: var(--radius-sm);
            border: 1px dashed var(--border-color);
        }

        .video-container {
            width: 200px;
            height: 120px;
            position: relative;
            border-radius: var(--radius-sm);
            overflow: hidden;
            background-color: #0f172a;
            box-shadow: var(--shadow-sm);
            transition: var(--transition);
        }

        .video-container:hover {
            transform: translateY(-3px);
            box-shadow: var(--shadow-md);
        }

        .video-thumbnail {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .video-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: var(--transition);
        }

        .video-container:hover .video-overlay {
            opacity: 1;
        }

        .play-btn {
            width: 40px;
            height: 40px;
            background-color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary-color);
            transform: scale(0.8);
            transition: var(--transition);
        }

        .video-container:hover .play-btn {
            transform: scale(1);
        }

        .video-duration {
            position: absolute;
            bottom: 5px;
            right: 5px;
            background-color: rgba(0, 0, 0, 0.7);
            color: white;
            font-size: 12px;
            padding: 2px 5px;
            border-radius: 3px;
        }

        .action-links {
            display: flex;
            gap: 10px;
        }

        .edit-link, .delete-link {
            padding: 6px 12px;
            border-radius: var(--radius-sm);
            font-size: 14px;
            text-decoration: none;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            gap: 5px;
        }

        .edit-link {
            background-color: var(--success-color);
            color: white;
        }

        .edit-link:hover {
            background-color: #059669;
            transform: translateY(-2px);
            box-shadow: 0 2px 5px rgba(16, 185, 129, 0.2);
        }

        .delete-link {
            background-color: var(--danger-color);
            color: white;
        }

        .delete-link:hover {
            background-color: #dc2626;
            transform: translateY(-2px);
            box-shadow: 0 2px 5px rgba(239, 68, 68, 0.2);
        }

        .price {
            color: var(--danger-color);
            font-weight: bold;
            font-size: 15px;
        }

        .no-goods {
            text-align: center;
            padding: 60px 30px;
            color: var(--text-light);
        }

        .no-goods i {
            font-size: 48px;
            margin-bottom: 20px;
            color: #cbd5e1;
        }

        .no-goods p {
            font-size: 16px;
            margin-bottom: 20px;
        }

        .pagination {
            display: flex;
            justify-content: center;
            margin-top: 30px;
            gap: 8px;
        }

        .page-btn {
            padding: 6px 12px;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-sm);
            background-color: white;
            color: var(--text-color);
            text-decoration: none;
            transition: var(--transition);
        }

        .page-btn:hover {
            background-color: var(--bg-color);
            border-color: var(--primary-color);
        }

        .page-btn.active {
            background-color: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }

        .page-btn.disabled {
            opacity: 0.5;
            cursor: not-allowed;
            pointer-events: none;
        }

        /* 视频模态框 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.8);
            z-index: 1000;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .modal.active {
            display: flex;
        }

        .modal-content {
            width: 100%;
            max-width: 1000px;
            background-color: white;
            border-radius: var(--radius-lg);
            overflow: hidden;
            position: relative;
            animation: modalFadeIn 0.3s ease;
        }

        @keyframes modalFadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .modal-header {
            padding: 15px 20px;
            background-color: var(--primary-color);
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-title {
            font-size: 18px;
            font-weight: 500;
        }

        .close-btn {
            background: none;
            border: none;
            color: white;
            font-size: 24px;
            cursor: pointer;
            transition: var(--transition);
        }

        .close-btn:hover {
            color: #f1f5f9;
            transform: rotate(90deg);
        }

        .modal-body {
            padding: 0;
        }

        .modal-video {
            width: 100%;
            height: 560px;
            border: none;
        }

        @media (max-width: 1200px) {
            .video-container {
                width: 160px;
                height: 90px;
            }
        }

        @media (max-width: 992px) {
            .container {
                padding: 20px;
            }

            .goods-table th,
            .goods-table td {
                padding: 12px;
            }

            .modal-video {
                height: 400px;
            }
        }

        @media (max-width: 768px) {
            .container {
                padding: 15px;
            }

            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }

            .header-actions {
                width: 100%;
                flex-direction: column;
                align-items: stretch;
            }

            .search-box input {
                width: 100%;
            }

            .search-box input:focus {
                width: 100%;
            }

            .goods-table {
                display: block;
                overflow-x: auto;
            }

            .video-container {
                width: 200px;
                height: 120px;
            }

            .action-links {
                flex-direction: column;
                gap: 5px;
            }

            .modal-video {
                height: 300px;
            }
        }

        @media (max-width: 576px) {
            .goods-img {
                width: 100px;
                height: 70px;
            }

            .no-image {
                width: 100px;
                height: 70px;
            }

            .modal-video {
                height: 200px;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h2><i class="fas fa-box-open"></i>商品列表</h2>
        <div class="header-actions">
            <div class="search-box">
                <i class="fas fa-search"></i>
                <input type="text" placeholder="搜索商品...">
            </div>
            <a href="${pageContext.request.contextPath}/goods/add" class="add-btn">
                <i class="fas fa-plus"></i>添加商品
            </a>
        </div>
    </div>

    <c:choose>
        <c:when test="${not empty goods}">
            <table class="goods-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th>学科名字</th>
                    <th>类型</th>
                    <th>作者</th>
                    <th>价格</th>
                    <th>视频</th>
                    <th>时长</th>
                    <th>描述</th>
                    <th>积分交换</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${goods}" var="goods">
                    <tr>
                        <td>${goods.gid}</td>
                        <td>
                            <c:choose>
                                <c:when test="${not empty goods.img}">
                                    <img class="goods-img" src="${goods.img}" alt="${goods.gname}">
                                </c:when>
                                <c:otherwise>
                                    <div class="no-image"><i class="fas fa-image"></i></div>
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td>${goods.gname}</td>
                        <td>${goods.type}</td>
                        <td>${goods.author}</td>
                        <td class="price">¥${goods.price}</td>
                        <td>
                            <c:choose>
                                <c:when test="${not empty goods.video}">
                                    <div class="video-container" onclick="openVideoModal('${goods.video}', '${goods.gname}')">
                                        <img src="https://picsum.photos/400/240?random=${goods.gid}" class="video-thumbnail" alt="视频缩略图">
                                        <div class="video-overlay">
                                            <div class="play-btn">
                                                <i class="fas fa-play"></i>
                                            </div>
                                        </div>
                                        <div class="video-duration">${goods.duration}</div>
                                    </div>
                                </c:when>
                                <c:otherwise>
                                    <div class="no-image"><i class="fas fa-video"></i></div>
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td>${goods.duration}</td>
                        <td>${goods.describe1}</td>
                        <td>${goods.scorerequired}</td>
                        <td>
                            <div class="action-links">
                                <a href="${pageContext.request.contextPath}/goods/edit/${goods.gid}" class="edit-link">
                                    <i class="fas fa-edit"></i>编辑
                                </a>
                                <a href="${pageContext.request.contextPath}/goods/delete/${goods.gid}"
                                   class="delete-link"
                                   onclick="return confirm('确定要删除此商品吗？此操作不可恢复！')">
                                    <i class="fas fa-trash"></i>删除
                                </a>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>

            <!-- 分页控件 -->
            <div class="pagination">
                <a href="#" class="page-btn disabled"><i class="fas fa-chevron-left"></i></a>
                <a href="#" class="page-btn active">1</a>
                <a href="#" class="page-btn">2</a>
                <a href="#" class="page-btn">3</a>
                <span>...</span>
                <a href="#" class="page-btn">8</a>
                <a href="#" class="page-btn"><i class="fas fa-chevron-right"></i></a>
            </div>
        </c:when>
        <c:otherwise>
            <div class="no-goods">
                <i class="fas fa-box"></i>
                <p>暂无商品数据</p>
                <a href="${pageContext.request.contextPath}/goods/add" class="add-btn">
                    <i class="fas fa-plus"></i>添加商品
                </a>
            </div>
        </c:otherwise>
    </c:choose>
</div>

<!-- 视频播放模态框 -->
<div id="videoModal" class="modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3 class="modal-title" id="modalTitle">视频播放</h3>
            <button class="close-btn" onclick="closeVideoModal()">&times;</button>
        </div>
        <div class="modal-body">
            <iframe id="modalVideo" class="modal-video" frameborder="0" allowfullscreen></iframe>
        </div>
    </div>
</div>

<script>
    function addUserIdToRequest(){
        var uid = getUid();
    }
    // 视频模态框控制
    function openVideoModal(videoUrl, title) {
        const modal = document.getElementById('videoModal');
        const modalVideo = document.getElementById('modalVideo');
        const modalTitle = document.getElementById('modalTitle');

        modalVideo.src = videoUrl;
        modalTitle.textContent = title;
        modal.classList.add('active');
        document.body.style.overflow = 'hidden'; // 防止背景滚动
    }

    function closeVideoModal() {
        const modal = document.getElementById('videoModal');
        const modalVideo = document.getElementById('modalVideo');

        modal.classList.remove('active');
        modalVideo.src = ''; // 停止视频播放
        document.body.style.overflow = ''; // 恢复背景滚动
    }

    // 点击模态框外部关闭
    document.getElementById('videoModal').addEventListener('click', function(e) {
        if (e.target === this) {
            closeVideoModal();
        }
    });

    // 增强删除确认对话框
    document.querySelectorAll('.delete-link').forEach(link => {
        link.addEventListener('click', function(e) {
            if(!confirm('确定要永久删除此商品吗？此操作不可撤销！')) {
                e.preventDefault();
            }
        });
    });

    // 搜索功能
    const searchInput = document.querySelector('.search-box input');
    searchInput.addEventListener('keyup', function(e) {
        const searchTerm = e.target.value.toLowerCase();
        // 这里可以添加实际搜索逻辑
        console.log('搜索:', searchTerm);
    });
</script>
</body>
</html>
